package cn.ekuma.pos.printer.zonerich;

import java.awt.image.BufferedImage;

import com.openbravo.pos.printer.DevicePrinter;
import com.openbravo.pos.printer.escpos.Codes;
import com.openbravo.pos.printer.escpos.PrinterWritter;
import com.openbravo.pos.printer.escpos.UnicodeTranslator;

public abstract class AbstractDevicePrinterChinaOEM {

	protected PrinterWritter m_CommOutputPrinter;

	protected Codes m_codes;
	protected UnicodeTranslator m_trans;

	public AbstractDevicePrinterChinaOEM() {
		super();
	}

	public void reset() {
	}

	public void beginReceipt() {
	}

	public void printImage(BufferedImage image) {   
	    m_CommOutputPrinter.write(m_codes.transImage(image));
	}

	public void printBarCode(String type, String position, String code) {
	
	    m_codes.printBarcode(m_CommOutputPrinter, type, position, code);
	}

	public void beginLine(int iTextSize) {    
	    
	    if (iTextSize == DevicePrinter.SIZE_0) {
	        m_CommOutputPrinter.write(m_codes.getSize0());
	    } else if (iTextSize == DevicePrinter.SIZE_1) {
	        m_CommOutputPrinter.write(m_codes.getSize1());
	    } else if (iTextSize == DevicePrinter.SIZE_2) {
	        m_CommOutputPrinter.write(m_codes.getSize2());
	    } else if (iTextSize == DevicePrinter.SIZE_3) {
	        m_CommOutputPrinter.write(m_codes.getSize3());
	    } else {
	        m_CommOutputPrinter.write(m_codes.getSize0());
	    }
	}

	public void printText(int iStyle, String sText) {
		
	    if ((iStyle & DevicePrinter.STYLE_BOLD) != 0) {
	        m_CommOutputPrinter.write(m_codes.getBoldSet());
	    }
	    if ((iStyle & DevicePrinter.STYLE_UNDERLINE) != 0) {
	        m_CommOutputPrinter.write(m_codes.getUnderlineSet());
	    }
	    m_CommOutputPrinter.write(m_trans.transString(sText));
	    if ((iStyle & DevicePrinter.STYLE_UNDERLINE) != 0) {
	        m_CommOutputPrinter.write(m_codes.getUnderlineReset());
	    }
	    if ((iStyle & DevicePrinter.STYLE_BOLD) != 0) {
	        m_CommOutputPrinter.write(m_codes.getBoldReset());
	    }      
	}

	public void endLine() {
	    m_CommOutputPrinter.write(m_codes.getNewLine());
	}

	public void endReceipt() {
	    m_CommOutputPrinter.flush();
	}

	public void openDrawer() {
	    m_CommOutputPrinter.write(m_codes.getOpenDrawer());
	    m_CommOutputPrinter.flush();
	}

	
	
	public void cutReceipt() {
		m_CommOutputPrinter.write(m_codes.getCutReceipt());
	}

}